View Javadoc

1   // Interface.java, created Fri Apr  5 18:36:41 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.sun14_win32;
5   
6   import java.util.Collections;
7   import java.util.Iterator;
8   import joeq.Class.PrimordialClassLoader;
9   import joeq.Class.jq_Class;
10  import joeq.ClassLib.ClassLibInterface;
11  import joeq.Runtime.ObjectTraverser;
12  import joeq.Scheduler.jq_NativeThread;
13  import jwutil.collections.AppendIterator;
14  
15  /*
16   * @author  John Whaley <jwhaley@alum.mit.edu>
17   * @version $Id: Interface.java 1941 2004-09-30 03:37:06Z joewhaley $
18   */
19  public class Interface extends joeq.ClassLib.Common.InterfaceImpl {
20  
21      /*** Creates new Interface */
22      public Interface() {}
23  
24      public Iterator getImplementationClassDescs(joeq.UTF.Utf8 desc) {
25          if (ClassLibInterface.USE_JOEQ_CLASSLIB && desc.toString().startsWith("Ljava/")) {
26              joeq.UTF.Utf8 u = joeq.UTF.Utf8.get("Ljoeq/ClassLib/sun14_win32/"+desc.toString().substring(1));
27              return new AppendIterator(super.getImplementationClassDescs(desc),
28                                        Collections.singleton(u).iterator());
29          }
30          return super.getImplementationClassDescs(desc);
31      }
32      
33      public ObjectTraverser getObjectTraverser() {
34          return sun14_win32ObjectTraverser.INSTANCE;
35      }
36      
37      public static class sun14_win32ObjectTraverser extends CommonObjectTraverser {
38          public static sun14_win32ObjectTraverser INSTANCE = new sun14_win32ObjectTraverser();
39          protected sun14_win32ObjectTraverser() {}
40          public void initialize() {
41              super.initialize();
42              
43              jq_Class k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/misc/Unsafe;");
44              nullStaticFields.add(k.getOrCreateStaticField("theUnsafe", "Lsun/misc/Unsafe;"));
45              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/reflect/UnsafeFieldAccessorImpl;");
46              nullStaticFields.add(k.getOrCreateStaticField("unsafe", "Lsun/misc/Unsafe;"));
47              
48              // leads to sun.nio.cs.UTF_8, etc.
49              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/nio/charset/Charset;");
50              nullStaticFields.add(k.getOrCreateStaticField("cache", "[Ljava/lang/Object;"));
51              
52              k = PrimordialClassLoader.getJavaLangClass();
53              nullInstanceFields.add(k.getOrCreateInstanceField("declaredFields", "Ljava/lang/ref/SoftReference;"));
54              nullInstanceFields.add(k.getOrCreateInstanceField("publicFields", "Ljava/lang/ref/SoftReference;"));
55              nullInstanceFields.add(k.getOrCreateInstanceField("declaredMethods", "Ljava/lang/ref/SoftReference;"));
56              nullInstanceFields.add(k.getOrCreateInstanceField("publicMethods", "Ljava/lang/ref/SoftReference;"));
57              nullInstanceFields.add(k.getOrCreateInstanceField("declaredConstructors", "Ljava/lang/ref/SoftReference;"));
58              nullInstanceFields.add(k.getOrCreateInstanceField("publicConstructors", "Ljava/lang/ref/SoftReference;"));
59              nullInstanceFields.add(k.getOrCreateInstanceField("declaredPublicFields", "Ljava/lang/ref/SoftReference;"));
60              nullInstanceFields.add(k.getOrCreateInstanceField("declaredPublicMethods", "Ljava/lang/ref/SoftReference;"));
61              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/lang/reflect/Field;");
62              nullInstanceFields.add(k.getOrCreateInstanceField("fieldAccessor", "Lsun/reflect/FieldAccessor;"));
63              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/lang/reflect/Method;");
64              nullInstanceFields.add(k.getOrCreateInstanceField("methodAccessor", "Lsun/reflect/MethodAccessor;"));
65              k = (joeq.Class.jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/lang/reflect/Constructor;");
66              nullInstanceFields.add(k.getOrCreateInstanceField("constructorAccessor", "Lsun/reflect/ConstructorAccessor;"));
67              
68              if (IGNORE_THREAD_LOCALS) {
69                  k = (joeq.Class.jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/lang/Thread;");
70                  nullInstanceFields.add(k.getOrCreateInstanceField("threadLocals", "Ljava/lang/ThreadLocal$ThreadLocalMap;"));
71                  nullInstanceFields.add(k.getOrCreateInstanceField("inheritableThreadLocals", "Ljava/lang/ThreadLocal$ThreadLocalMap;"));
72              }
73              
74              jq_NativeThread.USE_INTERRUPTER_THREAD = true;
75          }
76          
77          public static final jq_Class acp_class = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Lsun/nio/cs/AbstractCharsetProvider;");
78          
79          public java.lang.Object mapInstanceField(java.lang.Object o, joeq.Class.jq_InstanceField f) {
80              jq_Class c = f.getDeclaringClass();
81              if (c == acp_class) {
82                  String fieldName = f.getName().toString();
83                  if (fieldName.equals("cache")) {
84                      Object o2 = mappedObjects.get(o);
85                      if (o2 != null)
86                          return o2;
87                      o2 = new java.util.TreeMap(java.lang.String.CASE_INSENSITIVE_ORDER);
88                      mappedObjects.put(o, o2);
89                      return o2;
90                  }
91              }
92              return super.mapInstanceField(o, f);
93          }
94      }
95  }